Skip to content

gh-146250: Fix memory leak in re-initialization of SyntaxError#146251

Merged
kumaraditya303 merged 6 commits intopython:mainfrom
bkap123:syntax-error-leak
Mar 27, 2026
Merged

gh-146250: Fix memory leak in re-initialization of SyntaxError#146251
kumaraditya303 merged 6 commits intopython:mainfrom
bkap123:syntax-error-leak

Conversation

@bkap123
Copy link
Contributor

@bkap123 bkap123 commented Mar 21, 2026

Added Py_XDECREF/Py_XSETREF to avoid a memory leak when calling SyntaxError.__init__.

Added `Py_XDECREF`/`Py_XSETREF` to avoid a memory leak when calling
`SyntaxError.__init__`.
Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz
Copy link
Member

picnixz commented Mar 21, 2026

Sorry about the Py_CLEAR suggestion but I think creating new variables would be cleaner.

@bkap123
Copy link
Contributor Author

bkap123 commented Mar 21, 2026

What's wrong with using Py_CLEAR?

@picnixz
Copy link
Member

picnixz commented Mar 21, 2026

I think it is just better to hold temp vars and use XSETREF like in AttributeError.__init__

@picnixz
Copy link
Member

picnixz commented Mar 21, 2026

I will test the refleak bots so don't commit anything until they are done!

@picnixz picnixz added 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Mar 21, 2026
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit 22cff11 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F146251%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Mar 21, 2026
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I confirm that the added test leaks without the fix, and doesn't leak with the fix.

@kumaraditya303 kumaraditya303 merged commit 0de4e08 into python:main Mar 27, 2026
73 checks passed
@miss-islington-app
Copy link

Thanks @bkap123 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 27, 2026
pythonGH-146251)

(cherry picked from commit 0de4e08a5990e4692feb1b1ea01c303e468a2894)

Co-authored-by: Brij Kapadia <97006829+bkap123@users.noreply.github.com>
@miss-islington-app
Copy link

Sorry, @bkap123 and @kumaraditya303, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 0de4e08a5990e4692feb1b1ea01c303e468a2894 3.13

@bedevere-app
Copy link

bedevere-app bot commented Mar 27, 2026

GH-146517 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 27, 2026
@bkap123 bkap123 deleted the syntax-error-leak branch March 27, 2026 14:22
@bedevere-app
Copy link

bedevere-app bot commented Mar 27, 2026

GH-146519 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants